﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using DDU.Enums;
using DDU.DataModel;
using Microsoft.Phone.Controls;
using System.Windows;

namespace DDU.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public ObservableCollection<SemesterInfo> ItemsOfSemesters
        {
            get
            {
                if (IsDesignMode)
                {
                    return null;
                }
                if (Database.CollectionOfSemesters.Count() > 0)
                {
                    return new ObservableCollection<SemesterInfo>(Database.CollectionOfSemesters.OrderByDescending(s => s.StartTime));
                }
                return null;
            }
        }

        public SemesterInfo CurrentSemester
        {
            get
            {
                if (ItemsOfSemesters != null && ItemsOfSemesters.Count() > 0)
                {
                    DateTime now = DateTime.Now;
                    return ItemsOfSemesters.FirstOrDefault(s => s.StartTime < now && s.EndTime > now);
                }
                return null;
            }
        }
    }
}
